/*
 * Copyright (c) 2020 cloud4cloud Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bigbirdmed.cloud.admin.controller;


import com.bigbirdmed.cloud.admin.api.dto.SysLogDTO;
import com.bigbirdmed.cloud.admin.api.entity.SysLog;
import com.bigbirdmed.cloud.admin.api.vo.LogVO;
import com.bigbirdmed.cloud.admin.service.SysLogService;
import com.bigbirdmed.cloud.common.core.util.Pagination;
import com.bigbirdmed.cloud.common.core.util.R;
import com.bigbirdmed.cloud.common.security.annotation.Inner;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 日志表 前端控制器
 * </p>
 *
 * @author lengleng
 * @since 2019/2/1
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/log")
@Api(value = "log", tags = "日志管理模块")
public class LogController {

	private final SysLogService sysLogService;

	/**
	 * 分页查询
	 * @param dto 系统日志
	 * @return
	 */
	@PostMapping("/LogPage")
	public R<Pagination<LogVO.LogPageVO>> LogPage(@RequestBody SysLogDTO.LogPageDTO dto) {
		return sysLogService.LogPage(dto);
	}

	/**
	 * 删除日志
	 * @param dto
	 */
	@PostMapping("/removeByIds")
	public R<Void> removeByIds(@RequestBody  @Valid LogVO.RemoveByIdsDTO dto) {
		return sysLogService.removeByIds(dto);
	}

	/**
	 * 插入日志
	 * @param dto 日志实体
	 * @return success/false
	 */
	@Inner
	@PostMapping
	public R<Void> SaveLog(@RequestBody SysLogDTO.SaveLogDTO dto) {
		return sysLogService.SaveLog(dto);
	}

	/**
	 * 导出excel 表格
	 * @param dto 查询条件
	 * @return EXCEL
	 */
	@ResponseExcel(name = "导出日志Excel")
	@GetMapping("/exportLog")
	public List<LogVO.LogPageVO> exportLog(@RequestBody SysLogDTO.LogPageDTO dto) {
		return sysLogService.exportLog(dto);
	}


}
